package net.maku.utils;

import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;

import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

public class MyBeanUtils extends BeanUtils {

	public static <T, E> List<T> copyObjToList(List<E> orig, Class<T> destType){
        List<T> dest = new ArrayList<T>();
        if (CollectionUtils.isEmpty(orig)){
            return dest;
        }else {
            Iterator it = orig.iterator();
            while(it.hasNext()){
                E e = (E) it.next();
                T obj = BeanUtils.instantiateClass(destType);
                BeanUtils.copyProperties(e, obj);
                dest.add(obj);
            }
            return dest;
        }
	}
	
	public static <T> T copyObject( Object srcobj,  Class<T> destType ){
		T obj = BeanUtils.instantiateClass(destType);
		BeanUtils.copyProperties(srcobj, obj);
		return obj;
	}

}

